# !/usr/bin/env python
# encoding: utf-8
'''
  @author: HJW
  @license: (C) Copyright 2013-2017, Node Supply Chain Manager Corporation Limited.
  @contact: hejunwang01@126.com
  @file: api.py
  @time: 2024/4/14 0014 上午 10:16
  @desc:
  '''
import json
import logging
import time
import os

import pytest
import json,os
import requests

class Interface_api:
    '''
    API接口封装  get  post put delete 请求
    '''
    def __init__(self,url):
        self.url = url
        self.session = requests.session()

    def get_session(self,params = None,headers=None):
        '''
        session get
        :param params:
        :param headers:
        :return:
        '''
        res = self.session.get(url=self.url,params=params,headers=headers)
        return res

    def post_session(self,data,headers=None):
        '''
        session post
        :param data:
        :param headers:
        :return:
        '''
        res = self.session.post(url=self.url,data=data,headers=headers)
        return res

    def get_interface(self,params=None,headers=None):
        '''
        get 请求
        :param url:
        :param params:
        :param headers:
        :return:
        '''
        res = requests.get(url=self.url,params=params,headers=headers)
        # print(res)
        return  res


    def post_interface(self,data,headers=None):
        '''
        post 请求
        :param url:
        :param data:
        :param headers:
        :return:
        '''
        res = requests.post(url=self.url,data=data,headers=headers)
        return  res

    def put_interface(self,params,headers):
        '''
        put 请求
        :param url:
        :param data:
        :param headers:
        :return:
        '''
        res = requests.put(url=self.url,params=params, headers=headers)
        return  res
        pass

    def delete_interface(self,data,headers):
        '''
        delete 请求
        :param url:
        :param headers:
        :return:
        '''
        res = requests.delete(url=self.url,data=data, headers=headers)

        return  res


if __name__ == '__main__':

    url = 'https://www.xlvren.com/jweb_management/systemUser/login.json'
    params ={
            'username': '15039508071',
            'password':'e10adc3949ba59abbe56e057f20f883e'
            }
    headers = {
        # 'Content-Type':'application/json',
        'Content-Type':'application/x-www-form-urlencoded',  # 这里注意的是参数形式不一致
        'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.104 Safari/537.36'
    }
    # session = requests.session()
    # session.post(url=url,headers=headers,data=params)
    # cookie = session.cookies
    # print(cookie)

    api = Interface_api(url)
    res = api.get_interface(params,headers)
    print(res.content)
